package DesignPattern.ProxyPattern;

import java.lang.reflect.Proxy;

public class Client2 {
    public static void main(String[] args) {
        Movable tank = new Tank();
        MyTimeProxyInvocationHandler myTimeProxyInvocationHandler = new MyTimeProxyInvocationHandler(tank);
        Movable tankProxy = (Movable) Proxy.newProxyInstance
                (tank.getClass().getClassLoader(),
                        tank.getClass().getInterfaces(),
                        myTimeProxyInvocationHandler);
        tankProxy.move();
        System.out.println("--------------------");
        Flyable plane = new Plane();
        myTimeProxyInvocationHandler = new MyTimeProxyInvocationHandler(plane);
        // 为飞机产生代理, 为..产生代理，这样可以为很多东西产生代理，静态代理做不到
        Flyable planeProxy = (Flyable) Proxy.newProxyInstance(
                plane.getClass().getClassLoader(),
                plane.getClass().getInterfaces(),
                myTimeProxyInvocationHandler
        );
        planeProxy.fly();
    }
}
